/**
 * 
 */
package com.evon.yardmanagement.ui.action;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.ParameterAware;
import org.apache.struts2.interceptor.SessionAware;

import com.evon.yardmanagement.export.ExportDataManager;
import com.evon.yardmanagement.export.SectionExportableData;
import com.evon.yardmanagement.model.Section;
import com.evon.yardmanagement.service.SectionManagementService;

/**
 * @author Sandeep
 * 
 */
public class ExportSectionToExcel implements ParameterAware, SessionAware {

	private Map parameters;
	private Map<String, Object> session;

	SectionManagementService service = new SectionManagementService();
	List<Section> sections = service.getAllSectionsForExportToExcel();
	// availableYard = YardTransformer.transform(yards.get(0));
	private InputStream fileStream;

	public void setFileStream(InputStream arg) {
		fileStream = arg;
	}

	public InputStream getFileStream() {
		fileStream = new ByteArrayInputStream(exportSectionToExcelFile().toByteArray());
		return fileStream;
	}

	public String execute() {
		return "success";
	}

	private ByteArrayOutputStream exportSectionToExcelFile() {
		SectionExportableData exportableData = new SectionExportableData(sections);
		ExportDataManager<SectionExportableData> exportManager = new ExportDataManager<SectionExportableData>(exportableData);
		return exportManager.exportToExcel();
	}

	public Map getParameters() {
		return parameters;
	}

	public void setParameters(Map param) {
		System.out.println("set parameter");
		this.parameters = param;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public void setSession(Map<String, Object> arg0) {
		this.session = arg0;

	}

	public List<Section> getSections() {
		return sections;
	}

	public void setSections(List<Section> sections) {
		this.sections = sections;
	}

}
